import config
import logging

class RegisterLoginApi:



    # 获取图片验证码
    @classmethod
    def get_image_code(cls,session,r):
        url = config.Host + f"/common/public/verifycode1/{r}"
        resp = session.get(url)
        return resp

    # 获取短信验证码
    @classmethod
    def get_phone_code(cls,session,phone,imgVerifyCode):
        url = config.Host + f"/member/public/sendSms"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"phone":phone,
                "imgVerifyCode":imgVerifyCode,
                "type":"type"}
        logging.info(f"获取短信验证码接口的URL={url}")
        logging.info(f"获取短信验证码接口的请求体body={body}")
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 注册接口
    @classmethod
    def register(cls,session,phone,password,verifycode,phone_code):
        url = config.Host + f"/member/public/reg"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"phone":phone,
                "password":password,
                "verifycode":verifycode,
                "phone_code":phone_code,
                "dy_server":"on",
               }
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 登录接口
    @classmethod
    def login(cls,session,keywords,password):
        url = config.Host + f"/member/public/login"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"keywords":keywords,
                "password":password}
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 查询登录状态
    @classmethod
    def query_login_status(cls,session):
        url = config.Host + f"/member/public/islogin"
        resp = session.post(url)
        return resp